import HttpService from "@/api";
import type { DeptItem } from "@/typings/dept";

/**
 * @description 获取用户详细信息
 * @param userId 用户ID
 * @returns
 */
export const userApi = (userId: string) => HttpService.get<any>(`/system/user/${userId}`);

/**
 * @description 获取用户列表
 * @param params
 * @returns
 */
export const userListApi = (params?: any) => HttpService.get<DeptItem[]>(`/system/user/list`, { params });

/**
 * @description 新增用户
 * @param userForm 用户表单
 * @returns
 */
export const systemUserApi = (userForm: any) => HttpService.post<any>("/system/user", userForm);

/**
 * @description 修改用户
 * @param userForm 用户表单
 * @returns
 */
export const updateUserApi = (userForm: any) => HttpService.put<any>("/system/user", userForm);

/**
 * @description 获取用户详细信息
 * @param userId 用户id
 * @returns
 */
export const getUserByIdApi = (userId: number) => HttpService.get<any>(`/system/user/${userId}`);

/**
 * @description 删除用户
 * @param userIds 用户ID
 * @returns
 */
export const delUserApi = (userIds: string) => HttpService.delete<string>(`/system/user/${userIds}`);

/**
 * @description 获取用户详细信息
 * @param userId 用户ID
 * @returns
 */
export const userAutoRoleApi = (userId: string) => HttpService.get<any>(`/system/user/authRole/${userId}`);

/**
 * @description 获取已分配用户角色列表
 * @param roleId 角色ID
 * @returns
 */
export const allocatedListApi = (roleId: string) => HttpService.get<any>(`/system/role/authUser/allocatedList?roleId=${roleId}`);

/**
 * @description 获取未分配用户角色列表
 * @param
 * @returns
 */
export const unallocatedListApi = () => HttpService.get<any>(`/system/role/authUser/unallocatedList`);

/**
 * @description 获取所有角色列表
 * @param
 * @returns
 */
export const roleListApi = (params: any) => HttpService.get<any>(`/system/role/list`, { params });

/**
 * @description 取消授权用户
 * @param param
 * @returns
 */
export const authUserCancelApi = (param: any) => HttpService.put<any>("/system/role/authUser/cancel", param);

/**
 * @description 批量取消授权用户
 * @param param
 * @returns
 */
export const authUserCancelAllApi = (roleId: string, userIds: string) =>
  HttpService.put<any>(`/system/role/authUser/cancelAll?userIds=${userIds}&roleId=${roleId}`);

/**
 * @description 批量选择用户授权
 * @param param
 * @returns
 */
export const authUserSelectAllApi = (param: any) =>
  HttpService.put<any>(`/system/role/authUser/selectAll?roleId=${param.roleId}&userIds=${param.userIds}`);

/**
 * @description 用户角色授权
 * @param param
 * @returns
 */
export const authUserAuthRoleApi = (params: any) => HttpService.put<any>("/system/user/authRole", {}, { params });

/**
 * @description 重置用户密码
 * @param param
 * @returns
 */
export const resetPasswordApi = (params: any) => HttpService.put<any>("/system/user/reset", params);

/**
 * @description 获取部门树列表
 * @param
 * @returns
 */
export const deptTreeApi = () => HttpService.get<any>("/system/user/deptTree");

/**
 * @description 修改用户状态
 * @param param 状态
 * @returns
 */
export const userStatusApi = (param: any) => HttpService.put<any>("/system/user/status", param);

/**
 * @description 获取个人信息
 * @param
 * @returns
 */
export const getUserProfileApi = () => HttpService.get<any>("/system/user/profile");

/**
 * @description 修改用户信息
 * @param
 * @returns
 */
export const editUserProfileApi = (data: any) => HttpService.put<any>("/system/user/profile", data);

/**
 * @description 修改用户头像
 * @param
 * @returns
 */
export const editUserProfileAvatarApi = (data: any) => HttpService.post<any>("/system/user/profile/avatar", data);

/**
 * @description 重置用户密码
 * @param
 * @returns
 */
export const resetUserPasswordApi = (data: any) =>
  HttpService.put<any>(`/system/user/profile/resetPassword`, undefined, { params: data });
